//using Microsoft.VisualBasic;
using System;

//
// *  NHibernate 代码模版
// 

using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace NCS
{
	/// <summary>
	///	
	/// </summary>
	[Serializable()]
	public class VoltNew
	{
        //[DllImport("arrBstr", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        //public static extern int bstrToarr(ref byte vbstr, ref double p, int n);
        //[DllImport("arrBstr", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        //public static extern int arrTobstr(ref byte b, ref double v, int n);
        //[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
        //public static extern void CopyMemory(IntPtr pDst, IntPtr pSrc, System.Int32 ByteLen);
		#region "构造方法"
		public VoltNew()
		{
			m_sampleid = 0;
			m_mtimeArr = null;
			m_cvoltArr = null;
			m_svoltArr = null;
			m_c2voltArr = null;
			m_s2voltArr = null;
			m_xn = 0;
			m_yn0 = 0;
			m_yn1 = 0;
			m_yn2 = 0;

			m_yn3 = 0;
		}
        public virtual void createArr(int xn0)
        {
            m_xn = xn0;
            //m_mtimeArr = new byte[m_xn*8];
            //m_cvoltArr = new byte[m_xn*8];
            //m_svoltArr = new byte[m_xn*8];
            //m_c2voltArr = new byte[m_xn*8];
            //m_s2voltArr = new byte[m_xn*8];
            if (m_mtimeArr != null) { Array.Resize(ref m_mtimeArr, m_xn * 8); } else { m_mtimeArr = new byte[m_xn * 8]; }
            if (m_cvoltArr != null) { Array.Resize(ref m_cvoltArr, m_xn * 8); } else { m_cvoltArr = new byte[m_xn * 8]; }
            if (m_svoltArr != null) { Array.Resize(ref m_svoltArr, m_xn * 8); } else { m_svoltArr = new byte[m_xn * 8]; }
            if (m_c2voltArr != null) { Array.Resize(ref m_c2voltArr, m_xn * 8); } else { m_c2voltArr = new byte[m_xn * 8]; }
            if (m_s2voltArr != null) { Array.Resize(ref m_s2voltArr, m_xn * 8); } else { m_s2voltArr = new byte[m_xn * 8]; }
        }
        public virtual void toArr(ref double[] arr, int at)
        {
            switch (at)
            {
                case 0:
                    bstrToarr(ref m_cvoltArr,  ref arr, m_xn);
                    break;
                case 1:
                    bstrToarr(ref m_svoltArr, ref arr, m_xn);
                    break;
                case 2:
                    bstrToarr(ref m_c2voltArr, ref arr, m_xn);
                    break;
                case 3:
                    bstrToarr(ref m_s2voltArr, ref arr, m_xn);
                    break;
                case 4:
                    bstrToarr(ref m_mtimeArr, ref arr, m_xn);
                    break;

            }

        }
        public static  void bstrToarr(ref byte[] vbstr, ref double[] p, int n)
        {
            int size=sizeof(double)*n;
            //IntPtr  p_objTarget = Marshal.AllocHGlobal(size);
            //Marshal.Copy(vbstr, 0, p_objTarget, size);
            //Marshal.Copy(p_objTarget, p, 0, n);
            //Marshal.FreeHGlobal(p_objTarget);

            System.Buffer.BlockCopy(vbstr, 0, p, 0, size);

        }
        public static void  arrTobstr(ref byte[] b, ref double[] vdouble, int n)
        {
            int size = sizeof(double) * n;
            //IntPtr p_objTarget = Marshal.AllocHGlobal(size);
            //Marshal.Copy(vdouble, 0, p_objTarget, n);
            //Marshal.Copy(p_objTarget, b, 0, size);
            //Marshal.FreeHGlobal(p_objTarget);
            System.Buffer.BlockCopy(vdouble , 0, b, 0, size);

        }
        public virtual void loadArr(ref double[] arr, int at)
        {
            switch (at)
            { 
                case 0:
                    arrTobstr(ref m_cvoltArr, ref arr, m_xn);
                    break;
                case 1:
                    arrTobstr(ref m_svoltArr, ref arr, m_xn);
                    break;
                case 2:
                    arrTobstr(ref m_c2voltArr, ref arr, m_xn);
                    break;
                case 3:
                    arrTobstr(ref m_s2voltArr, ref arr, m_xn);
                    break;
                case 4:
                    arrTobstr(ref m_mtimeArr, ref arr, xn);
                    break;

            }
        }
		#endregion


		#region "私有变量"
		private int m_sampleid;
		private byte[] m_mtimeArr;
		private byte[] m_cvoltArr;
		private byte[] m_svoltArr;
		private byte[] m_c2voltArr;
		private byte[] m_s2voltArr;
		private int m_xn;
		private int m_yn0;
		private int m_yn1;
		private int m_yn2;

		private int m_yn3;
		#endregion


		#region "公有属性"

		///<summary>
		///
		///</summary>
		public virtual int sampleid {
			get { return m_sampleid; }
			set { m_sampleid = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual byte[] mtimeArr {
			get { return m_mtimeArr; }
			set { m_mtimeArr = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual byte[] cvoltArr {
			get { return m_cvoltArr; }
			set { m_cvoltArr = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual byte[] svoltArr {
			get { return m_svoltArr; }
			set { m_svoltArr = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual byte[] c2voltArr {
			get { return m_c2voltArr; }
			set { m_c2voltArr = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual byte[] s2voltArr {
			get { return m_s2voltArr; }
			set { m_s2voltArr = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual int xn {
			get { return m_xn; }
			set { m_xn = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual int yn0 {
			get { return m_yn0; }
			set { m_yn0 = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual int yn1 {
			get { return m_yn1; }
			set { m_yn1 = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual int yn2 {
			get { return m_yn2; }
			set { m_yn2 = value; }
		}

		///<summary>
		///
		///</summary>
		public virtual int yn3 {
			get { return m_yn3; }
			set { m_yn3 = value; }
		}

		#endregion

		#region "Rewrite Equals and HashCode"
		/// <summary>
		/// 
		/// </summary>
		public override bool Equals(object obj)
		{
			if (object.ReferenceEquals(this, obj)) {
				return true;
			}
			if ((obj == null) || (!object.ReferenceEquals(obj.GetType(), GetType()))) {
				return false;
			}
			VoltNew castObj = (VoltNew)obj;
			return (castObj != null) && (m_sampleid == castObj.sampleid);
		}
		/// <summary>
		/// 用唯一值实现GetHashCode
		/// </summary>
		public override int GetHashCode()
		{
			int hash = 57;
			hash = 27 * hash * m_sampleid.GetHashCode();
			return hash;
		}
		#endregion
	}
}
